const fs = require('fs')
const path = require('path')
const inquirer = require('inquirer')
const ejs = require('ejs')

inquirer
	.prompt([
		{
			type: 'input',
			name: 'name',
			message: '请输入项目名称'
		}
	])
	.then((answers) => {
		const srcPath = path.resolve(__dirname, './template/index.html')
		const destPath = path.resolve(process.cwd(), 'index.html')

		const tpl = fs.readFileSync(srcPath, 'utf8')
		const data = ejs.render(tpl, answers)
		fs.writeFileSync(destPath, data)
	})
	.catch((error) => {
		if (error.isTtyError) {
			// Prompt couldn't be rendered in the current environment
		} else {
			// Something else went wrong
		}
	})
